<!doctype html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="solr," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.0" />






<meta name="description" content="上一篇，我们介绍了如何搭建一个solr服务，这一篇，我们主要来实现一下，怎么将mysql的数据导入到solr服务中来，毕竟在平时的开发当中，首先肯定是将数据存在数据库的，所以对数据库数据建立索引很重要，下面废话不多说，进入主题。上一篇，我们已经建立了solr_home目录，solr_home在项目中我们是用来存储索引的，所以这一篇就从这里开始。
1 创建Core Admin在webapps中sol">
<meta property="og:type" content="article">
<meta property="og:title" content="solr实践（2）-- Solr6.2.0从Mysql上导入数据">
<meta property="og:url" content="http://www.taneroom.cn/2016/11/29/solr实践（2）-Solr6-2-0从Mysql上导入数据/index.html">
<meta property="og:site_name" content="TaneRoom">
<meta property="og:description" content="上一篇，我们介绍了如何搭建一个solr服务，这一篇，我们主要来实现一下，怎么将mysql的数据导入到solr服务中来，毕竟在平时的开发当中，首先肯定是将数据存在数据库的，所以对数据库数据建立索引很重要，下面废话不多说，进入主题。上一篇，我们已经建立了solr_home目录，solr_home在项目中我们是用来存储索引的，所以这一篇就从这里开始。
1 创建Core Admin在webapps中sol">
<meta property="og:image" content="http://img.blog.csdn.net/20161129100741657">
<meta property="og:image" content="http://img.blog.csdn.net/20161129100858158">
<meta property="og:image" content="http://img.blog.csdn.net/20161129100952659">
<meta property="og:image" content="http://img.blog.csdn.net/20161129101032447">
<meta property="og:updated_time" content="2016-11-29T03:03:12.508Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="solr实践（2）-- Solr6.2.0从Mysql上导入数据">
<meta name="twitter:description" content="上一篇，我们介绍了如何搭建一个solr服务，这一篇，我们主要来实现一下，怎么将mysql的数据导入到solr服务中来，毕竟在平时的开发当中，首先肯定是将数据存在数据库的，所以对数据库数据建立索引很重要，下面废话不多说，进入主题。上一篇，我们已经建立了solr_home目录，solr_home在项目中我们是用来存储索引的，所以这一篇就从这里开始。
1 创建Core Admin在webapps中sol">
<meta name="twitter:image" content="http://img.blog.csdn.net/20161129100741657">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://www.taneroom.cn/2016/11/29/solr实践（2）-Solr6-2-0从Mysql上导入数据/"/>





  <title> solr实践（2）-- Solr6.2.0从Mysql上导入数据 | TaneRoom </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  



  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?91ca0f0e00c720ad3b92033fd9766f4b";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>








  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">TaneRoom</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">低调的码农</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
  <link itemprop="mainEntityOfPage" href="http://www.taneroom.cn/2016/11/29/solr实践（2）-Solr6-2-0从Mysql上导入数据/">

  <span style="display:none" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <meta itemprop="name" content="TaneRoom">
    <meta itemprop="description" content="">
    <meta itemprop="image" content="/images/avatar.png">
  </span>

  <span style="display:none" itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
    <meta itemprop="name" content="TaneRoom">
    <span style="display:none" itemprop="logo" itemscope itemtype="http://schema.org/ImageObject">
      <img style="display:none;" itemprop="url image" alt="TaneRoom" src="">
    </span>
  </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                solr实践（2）-- Solr6.2.0从Mysql上导入数据
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2016-11-29T11:03:02+08:00">
                2016-11-29
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
              <span class="post-meta-divider">|</span>
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/solr实践/" itemprop="url" rel="index">
                    <span itemprop="name">solr实践</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <a href="/2016/11/29/solr实践（2）-Solr6-2-0从Mysql上导入数据/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="2016/11/29/solr实践（2）-Solr6-2-0从Mysql上导入数据/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          

          
          
             <span id="/2016/11/29/solr实践（2）-Solr6-2-0从Mysql上导入数据/" class="leancloud_visitors" data-flag-title="solr实践（2）-- Solr6.2.0从Mysql上导入数据">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               <span class="post-meta-item-text">阅读次数 </span>
               <span class="leancloud-visitors-count"></span>
              </span>
          

          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>上一篇，我们介绍了如何搭建一个solr服务，这一篇，我们主要来实现一下，怎么将mysql的数据导入到solr服务中来，毕竟在平时的开发当中，首先肯定是将数据存在数据库的，所以对数据库数据建立索引很重要，下面废话不多说，进入主题。<br>上一篇，我们已经建立了solr_home目录，solr_home在项目中我们是用来存储索引的，所以这一篇就从这里开始。</p>
<h2 id="1-创建Core-Admin"><a href="#1-创建Core-Admin" class="headerlink" title="1 创建Core Admin"></a>1 创建Core Admin</h2><p>在webapps中solrhome下新建一个文件夹名字叫做my_core（名字不固定，可以随便取，但是这个名字在后面的配置中会有所关联。）然后在my_core文件下新建一个名字叫做conf的文件夹（这个文件名字最后不要改。）然后把官网下下来的solr项目中solr-6.2.0\server\solr\configsets\data_driven_schema_configs\conf下的所有东西复制到conf中去。（注意不要复制错！）最后把solr-6.2.0\example\example-DIH\solr\db\conf下的admin-extra.html， admin-extra.menu-bottom.html ，admin-extra.menu-top.html三个文件也复制到conf中去。</p>
<h2 id="2-配置相关包及其路径"><a href="#2-配置相关包及其路径" class="headerlink" title="2 配置相关包及其路径"></a>2 配置相关包及其路径</h2><p>把mysql所需的jar包和solr-6.2.0\dist下的solr-dataimporthandler-6.2.0.jar和solr-dataimporthandler-extras-6.2.0.jar都复制到项目WEB-INF\lib下。然后在solrconfig.xml文件中加入<br><figure class="highlight nix"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">&lt;lib <span class="attr">dir="D:/编程工具/tomcat/apache-tomcat-8.0.32-windows-x64/apache-tomcat-8.0.32/webapps/solr/WEB-INF/lib/"</span> <span class="attr">regex=".*\.jar"</span> /&gt;</div></pre></td></tr></table></figure></p>
<p>就是把WEB-INF\lib里面的jar包配置到项目中，我这里用的是绝对地址。这段代码大约在solrconfig.xml的75行处，前面有一堆类似的代码。</p>
<h2 id="3-建立数据库表"><a href="#3-建立数据库表" class="headerlink" title="3 建立数据库表"></a>3 建立数据库表</h2><p>在MYSQL中新建一张表。我这里的表名叫goods，你也可以自己建，这个没有要求，主要是之后的配置，按数据表配就行了。我的建表语句如下：<br><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">CREATE</span> <span class="keyword">DATABASE</span> <span class="keyword">IF</span> <span class="keyword">NOT</span> <span class="keyword">EXISTS</span> solr;</div><div class="line"><span class="keyword">USE</span> solr;</div><div class="line"></div><div class="line"><span class="keyword">DROP</span> <span class="keyword">TABLE</span> <span class="keyword">IF</span> <span class="keyword">EXISTS</span> <span class="string">`goods`</span>;</div><div class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> <span class="string">`goods`</span> (</div><div class="line">  <span class="string">`id`</span> <span class="built_in">INT</span>(<span class="number">11</span>) <span class="keyword">NOT</span> <span class="literal">NULL</span> AUTO_INCREMENT,</div><div class="line">  <span class="string">`name`</span> <span class="built_in">VARCHAR</span>(<span class="number">10</span>) <span class="keyword">NOT</span> <span class="literal">NULL</span>,</div><div class="line">  <span class="string">`number`</span> <span class="built_in">INT</span>(<span class="number">20</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</div><div class="line">  <span class="string">`updateTime`</span> <span class="keyword">TIMESTAMP</span> <span class="literal">NULL</span> <span class="keyword">DEFAULT</span> <span class="keyword">CURRENT_TIMESTAMP</span>,</div><div class="line">  PRIMARY <span class="keyword">KEY</span> (<span class="string">`id`</span>)</div><div class="line">) <span class="keyword">ENGINE</span>=<span class="keyword">INNODB</span> AUTO_INCREMENT=<span class="number">5</span> <span class="keyword">DEFAULT</span> <span class="keyword">CHARSET</span>=utf8;</div><div class="line"><span class="keyword">INSERT</span>  <span class="keyword">INTO</span> <span class="string">`goods`</span>(<span class="string">`id`</span>,<span class="string">`name`</span>,<span class="string">`number`</span>,<span class="string">`updateTime`</span>) <span class="keyword">VALUES</span></div><div class="line">(<span class="number">1</span>,<span class="string">'商品1'</span>,<span class="number">100</span>,<span class="string">'2016-11-28 16:48:57'</span>),</div><div class="line">(<span class="number">2</span>,<span class="string">'商品2'</span>,<span class="number">120</span>,<span class="string">'2016-11-28 16:48:57'</span>),</div><div class="line">(<span class="number">3</span>,<span class="string">'商品3'</span>,<span class="number">150</span>,<span class="string">'2016-11-28 16:48:57'</span>),</div><div class="line">(<span class="number">4</span>,<span class="string">'手机1'</span>,<span class="number">50</span>,<span class="string">'2016-11-28 17:44:29'</span>);</div></pre></td></tr></table></figure></p>
<h2 id="4-添加data-config-xml"><a href="#4-添加data-config-xml" class="headerlink" title="4 添加data-config.xml"></a>4 添加data-config.xml</h2><p>在solrconfig.xml的<code>&lt;requestHandler name=&quot;/select&quot; class=&quot;solr.SearchHandler&quot;&gt;</code>之上添加：<br><figure class="highlight vbscript-html"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">&lt;requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler"&gt;</div><div class="line">    &lt;lst name="defaults"&gt;</div><div class="line">        &lt;str name="config"&gt;data-config.xml&lt;/str&gt;</div><div class="line">    &lt;/lst&gt;</div><div class="line">&lt;/requestHandler&gt;</div></pre></td></tr></table></figure></p>
<p>然后在conf下新建data-config.xml文件。内容如下：<br><figure class="highlight nix"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div></pre></td><td class="code"><pre><div class="line">&lt;?xml <span class="attr">version="1.0"</span> <span class="attr">encoding="UTF-8"?&gt;</span></div><div class="line">&lt;dataConfig&gt;</div><div class="line">    &lt;dataSource <span class="attr">name="source1"</span> <span class="attr">type="JdbcDataSource"</span> <span class="attr">driver="com.mysql.jdbc.Driver"</span></div><div class="line">        <span class="attr">url="jdbc:mysql://127.0.0.1:3306/solr"</span> <span class="attr">user="root"</span> <span class="attr">password="123456"</span> <span class="attr">batchSize="-1"</span> /&gt;</div><div class="line">    &lt;document&gt;</div><div class="line">        &lt;entity <span class="attr">name="goods"</span> <span class="attr">pk="id"</span>  <span class="attr">dataSource="source1"</span></div><div class="line">                <span class="attr">query="select</span> * from  goods<span class="string">"</span></div><div class="line">                deltaImportQuery="select * from goods where <span class="attr">id='$&#123;dih.delta.id&#125;'"</span></div><div class="line">                <span class="attr">deltaQuery="select</span> id from goods where updateTime &gt; '$&#123;dataimporter.last_index_time&#125;'<span class="string">"&gt;</span></div><div class="line">            &lt;field column="id<span class="string">" name="</span>id<span class="string">"/&gt;</span></div><div class="line">    　　　  &lt;field column="name<span class="string">" name="</span>name<span class="string">"/&gt;</span></div><div class="line">            &lt;field column="number<span class="string">" name="</span>number<span class="string">"/&gt;</span></div><div class="line">            &lt;field column="updateTime<span class="string">" name="</span>updateTime<span class="string">"/&gt;</span></div><div class="line">    　  &lt;/entity&gt;</div><div class="line">    &lt;/document&gt;</div><div class="line">&lt;/dataConfig&gt;</div></pre></td></tr></table></figure></p>
<p>解释一下：<br>dataSource是数据库数据源。Entity就是一张表对应的实体，pk是主键，query是查询语句。Field对应一个字段，column是数据库里的column名，后面的name属性对应着Solr的Filed的名字。其中solrdata是数据库名，goods是表名。<br>其中deltaQuery是增量索引，原理是从数据库中根据deltaQuery指定的SQL语句查询出所有需要增量导入的数据的ID号。然后根据deltaImportQuery指定的SQL语句返回所有这些ID的数据，即为这次增量导入所要处理的数据。核心思想是：通过内置变量“<code>${dih.delta.id}</code>”和 “<code>${dataimporter.last_index_time}</code>”来记录本次要索引的id和最近一次索引的时间。<br>最后在conf文件下的managed-schema配置field信息：<br><figure class="highlight nix"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">&lt;field <span class="attr">name="id"</span> <span class="attr">type="int"</span> <span class="attr">indexed="true"</span> <span class="attr">stored="true"</span> <span class="attr">required="true"</span> <span class="attr">multiValued="false"</span> /&gt;</div><div class="line">&lt;field <span class="attr">name="name"</span> <span class="attr">type="string"</span> <span class="attr">indexed="true"</span> <span class="attr">stored="false"/&gt;</span></div><div class="line">&lt;field <span class="attr">name="number"</span> <span class="attr">type="int"</span> <span class="attr">indexed="true"</span> <span class="attr">stored="false"/&gt;</span></div><div class="line">&lt;field <span class="attr">name="updateTime"</span> <span class="attr">type="date"</span> <span class="attr">indexed="true"</span> <span class="attr">stored="true"</span> /&gt;</div><div class="line"></div><div class="line">&lt;!--下面三个字段是系统本身不能删除的，删除会报错--&gt;</div><div class="line">&lt;field <span class="attr">name="_version_"</span> <span class="attr">type="long"</span> <span class="attr">indexed="true"</span> <span class="attr">stored="false"/&gt;</span></div><div class="line">&lt;field <span class="attr">name="_root_"</span> <span class="attr">type="string"</span> <span class="attr">indexed="true"</span> <span class="attr">stored="false"</span> <span class="attr">docValues="false"</span> /&gt;</div><div class="line">&lt;field <span class="attr">name="_text_"</span> <span class="attr">type="text_general"</span> <span class="attr">indexed="true"</span> <span class="attr">stored="false"</span> <span class="attr">multiValued="true"/&gt;</span></div></pre></td></tr></table></figure></p>
<p>注意：id,name,number,updateTime是我们上面数据库的字段。下面三个field是系统本身的不能删除，否则会运行错误。</p>
<h2 id="5-测试"><a href="#5-测试" class="headerlink" title="5 测试"></a>5 测试</h2><p>启动tomcat，并在URL中输入<a href="http://127.0.0.1:8080/solr/index.html" target="_blank" rel="external">http://127.0.0.1:8080/solr/index.html</a> 路径。在core Selector选择刚刚添加的core。<br><img src="http://img.blog.csdn.net/20161129100741657" alt="enter description here" title="选择core"><br>选择刚刚添加的goods实体进行索引操作：我们这儿可以选择full-import或者delta-import（增量索引），选择增量索引需要把clean的勾给去掉，不然会清除之前的，增量的索引的初衷是对新增或者修改的记录重新索引，会追加到原有的索引文件当中。当我们选择full-import的时候，最好就是把原有的索引文件给清空重新索引。<br><img src="http://img.blog.csdn.net/20161129100858158" alt="enter description here" title="导入数据"><br>索引成功如下如所示：<br><img src="http://img.blog.csdn.net/20161129100952659" alt="enter description here" title="索引成功"><br>使用query进行测试，输入关键字查出了想要的结果：<br><img src="http://img.blog.csdn.net/20161129101032447" alt="enter description here" title="query成功"><br>自此。mysql数据导入solr就顺利完成了，有什么问题下面留言吧</p>
<h2 id="6-相关参考"><a href="#6-相关参考" class="headerlink" title="6 相关参考"></a>6 相关参考</h2><p><a href="http://blog.csdn.net/linzhiqiang0316/article/details/51464461" target="_blank" rel="external">http://blog.csdn.net/linzhiqiang0316/article/details/51464461</a><br><a href="http://blog.csdn.net/u010379996/article/details/51799418" target="_blank" rel="external">http://blog.csdn.net/u010379996/article/details/51799418</a></p>

      
    </div>

    <div>
      
        
<div id="wechat_subscriber" style="display: block; padding: 10px 0; margin: 20px auto; width: 100%; text-align: center">
    <img id="wechat_subscriber_qcode" src="/images/donate/wechat.png" alt="TaneRoom wechat" style="width: 200px; max-width: 100%;"/>
    <div>请博主喝一杯咖啡！</div>
</div>


      
    </div>

    <div>
      
        

      
    </div>


    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/solr/" rel="tag"># solr</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2016/11/28/solr实践（1）-环境搭建/" rel="next" title="solr实践（1）-- Solr6.2.0环境搭建">
                <i class="fa fa-chevron-left"></i> solr实践（1）-- Solr6.2.0环境搭建
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
        <div class="ds-share flat" data-thread-key="2016/11/29/solr实践（2）-Solr6-2-0从Mysql上导入数据/"
     data-title="solr实践（2）-- Solr6.2.0从Mysql上导入数据"
     data-content=""
     data-url="http://www.taneroom.cn/2016/11/29/solr实践（2）-Solr6-2-0从Mysql上导入数据/">
  <div class="ds-share-inline">
    <ul  class="ds-share-icons-16">

      <li data-toggle="ds-share-icons-more"><a class="ds-more" href="javascript:void(0);">分享到：</a></li>
      <li><a class="ds-weibo" href="javascript:void(0);" data-service="weibo">微博</a></li>
      <li><a class="ds-qzone" href="javascript:void(0);" data-service="qzone">QQ空间</a></li>
      <li><a class="ds-qqt" href="javascript:void(0);" data-service="qqt">腾讯微博</a></li>
      <li><a class="ds-wechat" href="javascript:void(0);" data-service="wechat">微信</a></li>

    </ul>
    <div class="ds-share-icons-more">
    </div>
  </div>
</div>
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
      <div class="ds-thread" data-thread-key="2016/11/29/solr实践（2）-Solr6-2-0从Mysql上导入数据/"
           data-title="solr实践（2）-- Solr6.2.0从Mysql上导入数据" data-url="http://www.taneroom.cn/2016/11/29/solr实践（2）-Solr6-2-0从Mysql上导入数据/">
      </div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/avatar.png"
               alt="TaneRoom" />
          <p class="site-author-name" itemprop="name">TaneRoom</p>
          <p class="site-description motion-element" itemprop="description">低调的码农</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">11</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">2</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">12</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="http://weibo.com/u/2711247437" target="_blank" title="Weibo">
                  
                    <i class="fa fa-fw fa-weibo"></i>
                  
                  Weibo
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://blog.csdn.net/tanzhen1991910" target="_blank" title="CSDN">
                  
                    <i class="fa fa-fw fa-book"></i>
                  
                  CSDN
                </a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-创建Core-Admin"><span class="nav-number">1.</span> <span class="nav-text">1 创建Core Admin</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-配置相关包及其路径"><span class="nav-number">2.</span> <span class="nav-text">2 配置相关包及其路径</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-建立数据库表"><span class="nav-number">3.</span> <span class="nav-text">3 建立数据库表</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-添加data-config-xml"><span class="nav-number">4.</span> <span class="nav-text">4 添加data-config.xml</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-测试"><span class="nav-number">5.</span> <span class="nav-text">5 测试</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-相关参考"><span class="nav-number">6.</span> <span class="nav-text">6 相关参考</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2016</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">TaneRoom</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>


        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.0"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.0"></script>



  

  
    
  

  <script type="text/javascript">
    var duoshuoQuery = {short_name:"taneroom"};
    (function() {
      var ds = document.createElement('script');
      ds.type = 'text/javascript';ds.async = true;
      ds.id = 'duoshuo-script';
      ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
      ds.charset = 'UTF-8';
      (document.getElementsByTagName('head')[0]
      || document.getElementsByTagName('body')[0]).appendChild(ds);
    })();
  </script>

  
    
    
    <script src="/lib/ua-parser-js/dist/ua-parser.min.js?v=0.7.9"></script>
    <script src="/js/src/hook-duoshuo.js"></script>
  








  
  

  

  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.1.js"></script>
  <script>AV.initialize("BnRa0PjEwPETnK8UggnNxrvQ-gzGzoHsz", "gTNTrFanjWAJhrkpXA6VDjbf");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


  


</body>
</html>
